<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录测试页面</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 600px;
            margin: 50px auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            background: white;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        .form-group {
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        input {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        button {
            background-color: #409eff;
            color: white;
            padding: 12px 24px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            margin-right: 10px;
        }
        button:hover {
            background-color: #66b1ff;
        }
        .result {
            margin-top: 20px;
            padding: 15px;
            border-radius: 4px;
            white-space: pre-wrap;
        }
        .success {
            background-color: #f0f9ff;
            border: 1px solid #b3d8ff;
            color: #0066cc;
        }
        .error {
            background-color: #fef0f0;
            border: 1px solid #fbc4c4;
            color: #cc0000;
        }
    </style>
</head>
<body>
    <div class="container">
        <h2>登录功能测试</h2>
        
        <div class="form-group">
            <label for="username">用户名:</label>
            <input type="text" id="username" value="testuser" placeholder="请输入用户名">
        </div>
        
        <div class="form-group">
            <label for="password">密码:</label>
            <input type="password" id="password" value="123456" placeholder="请输入密码">
        </div>
        
        <button onclick="testLogin()">测试登录</button>
        <button onclick="testRegister()">测试注册</button>
        <button onclick="clearResult()">清除结果</button>
        
        <div id="result" class="result" style="display: none;"></div>
    </div>

    <script>
        const API_BASE = 'http://localhost:8080';
        
        function showResult(message, isSuccess = true) {
            const resultDiv = document.getElementById('result');
            resultDiv.style.display = 'block';
            resultDiv.className = `result ${isSuccess ? 'success' : 'error'}`;
            resultDiv.textContent = message;
        }
        
        function clearResult() {
            document.getElementById('result').style.display = 'none';
        }
        
        async function testLogin() {
            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;
            
            if (!username || !password) {
                showResult('请输入用户名和密码', false);
                return;
            }
            
            try {
                const response = await fetch(`${API_BASE}/api/users/login`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        username: username,
                        password: password
                    })
                });
                
                const data = await response.json();
                
                if (data.success) {
                    showResult(`登录成功！\n用户信息：\n${JSON.stringify(data.data, null, 2)}`);
                } else {
                    showResult(`登录失败：${data.message}`, false);
                }
            } catch (error) {
                showResult(`请求失败：${error.message}`, false);
            }
        }
        
        async function testRegister() {
            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;
            
            if (!username || !password) {
                showResult('请输入用户名和密码', false);
                return;
            }
            
            try {
                const response = await fetch(`${API_BASE}/api/test/users/register`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        username: username,
                        name: '测试用户',
                        phone: '13800138000',
                        email: 'test@example.com',
                        password: password
                    })
                });
                
                const data = await response.json();
                
                if (data.success) {
                    showResult(`注册成功！\n用户信息：\n${JSON.stringify(data.data, null, 2)}`);
                } else {
                    showResult(`注册失败：${data.message}`, false);
                }
            } catch (error) {
                showResult(`请求失败：${error.message}`, false);
            }
        }
    </script>
</body>
</html>


